/*
============================================================================
 Name		: Jpg2Bitmap.cpp
 Author	  : ceze
 Version	 :
 Copyright   : FlashBox for ver.Zhongyou(???)
 Description : CJpg2Bitmap implementation
============================================================================
*/
#include <ImageConversion.h>
#include <EIKENV.H>
#include "Jpg2Bitmap.h"
#include "BAUTILS.H" // bafl.lib 

CJpg2Bitmap::CJpg2Bitmap()
{
	// No implementation required
}


CJpg2Bitmap::~CJpg2Bitmap()
{
}

CJpg2Bitmap* CJpg2Bitmap::NewLC()
{
	CJpg2Bitmap* self = new (ELeave)CJpg2Bitmap();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
}

CJpg2Bitmap* CJpg2Bitmap::NewL()
{
	CJpg2Bitmap* self=CJpg2Bitmap::NewLC();
	CleanupStack::Pop(); // self;
	return self;
}

void CJpg2Bitmap::ConstructL()
{

}


CFbsBitmap * CJpg2Bitmap::BitmapFromJpgFile(const TDesC &aFilePath)
{
	RFs rfs = CEikonEnv::Static()->FsSession();
	//判断文件是否存在 ( bafl.lib )
	if(!BaflUtils::FileExists(rfs, aFilePath))
		return NULL;

	CImageDecoder* pImgDec = CImageDecoder::FileNewL (rfs, aFilePath, CImageDecoder::EOptionAlwaysThread);
	CFbsBitmap* pTempBmp = new(ELeave) CFbsBitmap();
	pTempBmp->Create (pImgDec->FrameInfo().iOverallSizeInPixels, pImgDec->FrameInfo().iFrameDisplayMode);
	TRequestStatus iStatus = KErrNone;
	pImgDec->Convert (&iStatus, *(pTempBmp));
	User::WaitForRequest( iStatus );

	delete pImgDec;
	return pTempBmp;
//	return NULL;
}

